import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
    state: {
        user: localStorage.getItem('user') ? localStorage.getItem('user') : null,
        token: localStorage.getItem('token') ? localStorage.getItem('token') : null,
        blogs: "默认值",
        editType: "",
        keyword: ""
    },
    mutations: {
        setUser(state, user) {
            state.user = user
            localStorage.setItem('user', JSON.stringify(user))
        },
        setToken(state, token) {
            localStorage.setItem('token', token)
            state.token = token
        },
        logout(state) {
            localStorage.removeItem('token')
            state.token = null
            localStorage.removeItem('user')
            state.user = null
        },
        setBlogs(state, blogs) {
            state.blogs = blogs
        },
        setEditType(state, type) {
            state.editType = type
        },
        setKeyword(state, keyword) {
            state.keyword = keyword
        }
    }
})